package top.lyc829.leetcode.T206;


class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}

class Solution {
    public ListNode reverseList(ListNode head) {

        // 迭代法
        ListNode first = new ListNode(0, null);
        while (head != null) {
            ListNode tmp = head;
            head = head.next;
            tmp.next = first.next;
            first.next = tmp;
        }

        return first.next;
    }
}